home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
STANDALO
/
F1-F4
/
F1-F4.C
next >
Wrap
Text File
|
1990-05-09
|
3KB
|
130 lines
/*
"F1-F4.c"
INIT that patches _PostEvent so that the function keys F1 to F4 on
the Apple extended keyboard behave as they should in most applications.
This patch checks to see if the event is a keyDown event. If it is the
function keys F1, F2, F3 and F4 are translated to command-Z (undo),
command-X (cut), command-C (copy) and command-V (paste) respectively.
That's all there is, easy isn't it?
"Set Project Type..." for THINK C 4.02:
Code resource on
File type INIT
Creator ????
Name F1-F4
Type INIT
ID 128
Custom header checked
Attrs 00
Erny Tontlinger version 1.0 09-May-1990
*/
#define POSTEVENT 0xA02F /* Trap to patch */
#define JMPopc 0x4EF9 /* Used for self-modifying code */
#define CmdByte 0x174+6 /* KeyMap+6 */
#define CmdBit 7 /* Bit for command key */
/* #define CLEANUP */
void main (void)
{
asm {
;Called here at INIT time
;========================
MOVEM.L D4-D5,-(SP)
MOVE #POSTEVENT,D0 ;Save original trap address
_GetTrapAddress
LEA @OrigTrap,A1
MOVE.L A0,(A1)
LEA @Last,A0 ;Move patch into system heap
LEA @Patch,A1 ;(It's a shame we cannot use
SUBA.L A1,A0 ; MOVE.L #@Last-@Patch,D0)
MOVE.L A0,D4 ;D4 = byte count
MOVE.L A0,D0
_NewPtr SYS
BNE.S @NoPatch ;No memory available
MOVE.L A0,D5 ;D5 = destination
MOVE #POSTEVENT,D0 ;Set our patch
_SetTrapAddress
LEA @Patch,A0 ;Move patch into place
MOVE.L D5,A1 ;Destination
MOVE.L D4,D0 ;Byte count
_BlockMove
@NoPatch
MOVEM.L (SP)+,D4-D5 ;Restore registers
RTS ; and return
;New _PostEvent
;==============
;On entry: A0: eventCode (word)
; D0: eventMsg (long word)
;On exit: DO: result code (word)
@Patch
CMPI #keyDown,A0 ;keyDown event?
BNE.S @Return2
CMPI.B #0x10,D0 ;Function key?
BNE.S @Return2
MOVE.L A0,-(SP)
ROR #8,D0 ;Key code ==> character code
LEA @FunctionKeys,A0 ;Check for F1-F4
BRA.S @Test
@Loop
CMP.B (A0)+,D0
BNE.S @Test
#ifdef CLEANUP
LEA @Exit,A0 ;Save original return address
MOVE.L 4(SP),(A0)
LEA @Tail,A0 ;Set return address to
MOVE.L A0,4(SP) ; our tail patch
#endif
MOVE.L #CmdByte,A0 ;Set bit in "KeyMap" corresponding
BSET.B #CmdBit,(A0) ; to command key
BRA.S @Return1
@Test
TST.B (A0)
BNE.S @Loop
ROR #8,D0 ;Restore original D0
@Return1
MOVE.L (SP)+,A0 ;Restore original A0
@Return2
DC JMPopc ;Jump to original _PostEvent
@OrigTrap
DC.L 0
#ifdef CLEANUP
;_PostEvent returns here
;=======================
;(This seems not to be necessary)
@Tail
MOVE.L A0,-(SP)
MOVE.L #CmdByte,A0 ;Clear bit in "KeyMap" corresponding
BCLR.B #CmdBit,(A0) ; to command key
MOVE.L (SP)+,A0
DC JMPopc ;Return to original caller
@Exit
DC.L 0
#endif
;Data
;====
@FunctionKeys DC.B 'z','x','c','v',0 ;undo, cut, copy, paste
@Last
}
}